import { notNilEmpty } from 'qx-util';
import { LogUtil } from '../../core';
import { IPSDEUIActionLogic } from '../../dataentity/logic/ipsdeuiaction-logic';
import { IPSDEUIDEActionLogic } from '../../dataentity/logic/ipsdeuideaction-logic';
import { IPSModelObject } from '../../ipsmodel-object';
import { PSModelServiceProxyImpl } from '../../psmodel-service-proxy-impl';

/**
 * 全局默认通用代理
 *
 * @author chitanda
 * @date 2021-06-08 20:06:55
 * @export
 * @class PSAppDEUILogicNodeServiceProxy
 * @extends {PSModelServiceProxyImpl}
 */
export class PSAppDEUILogicNodeServiceProxy extends PSModelServiceProxyImpl {
  getPSModel4(
    relatedPSModelObject: IPSModelObject,
    cls: string,
    objNode: any,
    strTag: string,
  ): IPSModelObject {
    switch (strTag) {
      case 'getDstPSAppDEAction':
        return this.getDstPSAppDEAction(
          relatedPSModelObject as IPSDEUIDEActionLogic,
          objNode,
        );
      case 'getDstPSAppDEUIAction':
        return this.getDstPSAppDEUIAction(
          relatedPSModelObject as IPSDEUIActionLogic,
          objNode,
        );
    }
    return this.getRealPSModelService().getPSModel4(
      relatedPSModelObject,
      cls,
      objNode,
      strTag,
    );
  }

  getDstPSAppDEAction(r: IPSDEUIDEActionLogic, obj: any): any {
    if (obj.modelref) {
      const entity = r.getDstPSAppDataEntity();
      if (notNilEmpty(entity)) {
        if (entity.isFill) {
          return entity.findPSAppDEMethod(obj);
        } else {
          LogUtil.warn('实体未填充，无法查找实体行为!', entity);
        }
      }
    }
    return null;
  }

  getDstPSAppDEUIAction(r: IPSDEUIActionLogic, obj: any): any {
    if (obj.modelref) {
      const entity = r.getDstPSAppDataEntity();
      if (notNilEmpty(entity)) {
        if (entity.isFill) {
          return entity.findPSAppDEUIAction(obj);
        } else {
          LogUtil.warn('实体未填充，无法查找实体界面行为!', entity);
        }
      }
    }
    return null;
  }
}
